package com.zc.service.picture;

import com.zc.dao.ImageMapper;
import com.zc.dao.ImgInfoMapper;
import com.zc.entity.Image;
import com.zc.entity.ImgInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PhotoUploadService {
    @Resource
    private ImageMapper dao;
    @Resource
    private ImgInfoMapper imgDao;
    public void save(Image image) throws Exception{
        dao.save(image);
    }

    public void updatePicture(Image img) {
        dao.updateByPrimaryKeySelective(img);
    }

    public void updateRank(String rank) {
        String[] ssk= rank.split(",");
        Image four=null;

        for(int i=0;i<ssk.length;i++){
            four=new Image();
            String ss=ssk[i].substring(ssk[i].lastIndexOf("/")+1,ssk[i].length());
            four.setId(i+1);
            four.setPicUrl(ss);
            dao.updateByPrimaryKeySelective(four);
        }
    }

    public void saveImg(List<String> urls) {
        ImgInfo img = null ;
        for(String string:urls){
            img= new ImgInfo();
            img.setImgurl(string);
            imgDao.insertSelective(img);
        }
    }
}
